home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / m_to_r / rr65 / rrsql65.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  34.5 KB  |  1,097 lines

  1. { Delphi Object for R&R V6.5 SQL Edition }
  2.  
  3. { Author Chris Brooksbank (cbrooksbank@msn.com) }
  4. { Written : October 1995 }
  5.  
  6. unit RRSQL65;
  7.  
  8. interface
  9.  
  10. uses
  11.   SysUtils,WinTypes,WinProcs,Messages,Classes,Graphics,Controls,Forms,
  12.   Dialogs,rrsqlint;
  13.  
  14. type
  15.   TrrFilterUsage = (rrfuSaved,rrfuNone,rrfuComponent,rrfuInteractive);
  16.   TrrDest = (rrdDisplay,rrdTextFile,rrdPrinter,rrdWorksheet,rrdXBase,
  17.              rrdInteractive,rrdCSV,rrdMSWord,rrdRTF);
  18.   TrrExportDest = (rredDisplay,rredFile,rredPrinter);
  19.   TrrwsBorderStyle = (rrwsNone,rrwsFixedSingle,rrwsSizable,rrwsFixedDouble);
  20.  
  21.   TRRSQL65 = class(TComponent)
  22.   private
  23.     { Private declarations }
  24.  
  25.      { SQL Specfic Fields Follow }
  26.      fAskDataSource:Boolean;
  27.      fAskTable:Boolean;
  28.      fDataSource: String;
  29.      fJoinTablenames: TStrings;
  30.      fJoinAliasNames: TStrings;
  31.      fPassword: String;
  32.      fReplaces: TStrings;
  33.      fUserName: String;
  34.      fWhere:String;
  35.  
  36.      { Generic Fields Follow }
  37.      fActive:Boolean;
  38.      fAskPrinter:Boolean;
  39.      fAskReport:Boolean;
  40.      fAuthor:String;
  41.      fAppName:String;
  42.      fBeginPage: Longint;
  43.      fCopies: Longint;
  44.      fDatabasename: String;
  45.      fDataDir    : String;
  46.      fDisplayErrors: Boolean;
  47.      fDisplayStatus: Boolean;
  48.      fEndPage: LongInt;
  49.      fErrorCode: String;
  50.      fErrorMessage: String;
  51.      fExportDest: TrrExportDest;
  52.      fFields: TStrings;
  53.      fFilter: String;
  54.      fFilterUsage: TrrFilterUsage;
  55.      fGroupFields: TStrings;
  56.      fImageDir   : String;
  57.      fLastErrorPage: Longint;
  58.      fLibName: String;
  59.      fMasterTableName: String;
  60.      fMemoName: String;
  61.      fOutputDest: TRRDest;
  62.      fOutputFile: String;
  63.      fPreventEscape: Boolean;
  64.      fPrinterName: String;
  65.      fPrinterPort: String;
  66.      fRepName:String;
  67.      fReportPick: Boolean;
  68.      fSortFields: TStrings;
  69.      fStatusEveryPage: Boolean;
  70.      fSuppressTitle: Boolean;
  71.      fTestPattern: Boolean;
  72.      fUserParamsNames: TStrings;
  73.      fUserParamsValues: TStrings;
  74.      fVersion: String;
  75.      fWait: Boolean;
  76.      fWinBorderStyle: TrrwsBorderStyle;
  77.      fWinControlBox: Boolean;
  78.      fWinHeight: Integer;
  79.      fWinLeft:Integer;
  80.      fWinMaxButton: Boolean;
  81.      fWinMinButton: Boolean;
  82.      fWinParentHandle: Integer;
  83.      fWinTitle: String;
  84.      fWinTop: Integer;
  85.      fWinWidth:Integer;
  86.  
  87.  
  88.      { SQL Specific private functions follow }
  89.  
  90.      procedure LoadJoins(hReport:Integer);
  91.      procedure setfJoinTableNames(Value:Tstrings);
  92.      procedure setfJoinAliasNames(Value:Tstrings);
  93.      procedure setfReplaces(Value:Tstrings);
  94.      procedure savereplaces(hReport:Integer);
  95.      procedure loadreplaces(hReport:Integer);
  96.      procedure loaddatasource(hReport:Integer);
  97.      procedure LoadFromReportH(hMyReport:Integer);
  98.  
  99.      { Generic functions follow }
  100.  
  101.      procedure setfActive(Value:Boolean);
  102.      procedure setfAuthor(Value:String);
  103.      procedure LoadFields(hReport:Integer);
  104.      procedure LoadGroupFields(hReport:Integer);
  105.      procedure LoadSortFields(hReport:Integer);
  106.      procedure LoadUserParams(hReport:Integer);
  107.      procedure LoadTitle(hReport:Integer);
  108.      procedure LoadPages(hReport:Integer);
  109.      procedure LoadTable(hReport:Integer);
  110.      procedure LoadFilter(hReport:Integer);
  111.      procedure LoadDests(hReport:Integer);
  112.      procedure LoadPrinter(hReport:Integer);
  113.  
  114.      procedure setfFields(Value:Tstrings);
  115.      procedure setfGroupFields(Value:Tstrings);
  116.      procedure setfSortFields(Value:Tstrings);
  117.      procedure setfUserParamsNames(Value:Tstrings);
  118.      procedure setfUserParamsValues(Value:Tstrings);
  119.      procedure SetLibName(NewLibName:String);
  120.      procedure SetRepName(NewRepName: String);
  121.      procedure SaveToReportH(hReport:Integer);
  122.  
  123.   protected
  124.     { Protected declarations }
  125.   public
  126.     { Public declarations }
  127.     constructor Create(Aowner:TComponent); override;
  128.     destructor Free;
  129.     function execute:Boolean;
  130.     function run:Boolean;
  131.     procedure LoadFromReport;
  132.     function SaveToFile(MyFile:String):Boolean;
  133.     function LoadFromFile(MyFile:String):Boolean;
  134.  
  135.   published
  136.     { Published declarations }
  137.  
  138.     { SQL Specific Properties Follow }
  139.  
  140.     property AskDataSource:Boolean read fAskDataSource write fAskDataSource;
  141.     property AskTable:Boolean read fAskTable write fAskTable;
  142.     property DataSource: String read fDataSource write fDataSource;
  143.     property JoinTableNames: TStrings read fJoinTableNames
  144.                                       write setfJoinTableNames;
  145.     property JoinAliasNames: TStrings read fJoinAliasNames
  146.                                       write setfJoinAliasNames;
  147.     property Password: String read fPassword write fPassword;
  148.     property Replaces:Tstrings read fReplaces write SetfReplaces;
  149.     property UserName: String read fUserName write fUserName;
  150.     property Where: String read fWhere write fWhere;
  151.  
  152.     { Generic Properties follow }
  153.  
  154.     property Active: Boolean read fActive write SetfActive;
  155.     property AppName: String read fAppName write fAppName;
  156.     property AskPrinter:Boolean read fAskPrinter write fAskPrinter;
  157.     property AskReport:Boolean read fAskReport write fAskReport;
  158.     property Author: String read fAuthor write setfAuthor;
  159.     property BeginPage: Longint read fBeginPage write fBeginPage;
  160.     property Copies: Longint read fCopies write fCopies;
  161.     property Databasename:String read fDatabasename write fDatabasename;
  162.     property DataDirectory:String read fDataDir write fDataDir;
  163.     property DisplayErrors: Boolean read fDisplayErrors write fDisplayErrors;
  164.     property DisplayStatus: Boolean read fDisplayStatus write fDisplayStatus;
  165.     property EndPage: Longint read fEndPage write fEndPage;
  166.     property ErrorCode: String read fErrorcode write fErrorcode;
  167.     property ErrorMessage: String read fErrorMessage write fErrorMessage;
  168.     property ExportDest: TrrExportDest read fExportDest write fExportDest;
  169.     property Fields: TStrings read fFields write setfFields;
  170.     property Filter: String read fFilter write fFilter;
  171.     property FilterUsage: TrrFilterUsage read fFilterUsage write fFilterUsage;
  172.     property GroupFields: TStrings read fGroupFields write setfGroupFields;
  173.     property ImageDir: String read fImageDir write fImageDir;
  174.     property LastErrorPage:Longint read fLastErrorPage write fLastErrorPage;
  175.     property MasterTableName: String read fMasterTableName write fMasterTableName;
  176.     property MemoName: String read fMemoName write fMemoName;
  177.     property OutputDest: TrrDest read fOutputDest write fOutputDest;
  178.     property OutputFile: String read fOutputFile write fOutputFile;
  179.     property PreventEscape: Boolean read fPreventEscape write fPreventEscape;
  180.     property PrinterName: String read fPrinterName write fPrinterName;
  181.     property PrinterPort: String read fPrinterPort write fPrinterPort;
  182.     property ReportLibrary:String read fLibName write setLibName;
  183.     property ReportName: String read fRepName write setRepName;
  184.     property SortFields: TStrings read fSortFields write setfSortFields;
  185.     property StatusEveryPage: Boolean read fStatusEveryPage
  186.                                       write fStatusEveryPage;
  187.     property SuppressTitle: Boolean read fSuppressTitle write fSuppressTitle;
  188.     property TestPattern: Boolean read fTestPattern write fTestPattern;
  189.     property UserParamsNames: TStrings read fUserParamsNames
  190.                                        write setfUserParamsNames;
  191.     property UserParamsValues: TStrings read fUserParamsValues
  192.                                        write setfUserParamsValues;
  193.     property Version:String read fVersion write fversion;
  194.     property Wait: Boolean read fWait write fWait;
  195.     property WinBorderStyle:TrrwsBorderStyle read fWinBorderStyle
  196.              write fWinBorderStyle;
  197.     property WinControlBox: Boolean read fWinControlBox write fWinControlBox;
  198.     property WinHeight: Integer read fWinHeight write fWinHeight;
  199.     property WinLeft: Integer read fWinLeft write fWinLeft;
  200.     property WinMaxButton: Boolean read fWinMaxButton write fWinMaxButton;
  201.     property WinMinButton: Boolean read fWinMinButton write fWinMinButton;
  202.     property WinParentHandle: Integer read fWinParentHandle write fWinParentHandle;
  203.     property WinTitle: String read fWinTitle write fWinTitle;
  204.     property WinTop:Integer read fWinTop write fWinTop;
  205.     property WinWidth:Integer read fWinWidth write fWinWidth;
  206.  
  207. end;
  208.  
  209. procedure Register;
  210.  
  211. implementation
  212.  
  213. { ************************************************************************** }
  214. constructor TRRSQL65.create(AOwner:Tcomponent);
  215. { ************************************************************************** }
  216. begin
  217.   inherited create(AOwner);
  218.  
  219.   initruntimeinstance;
  220.  
  221.   { SQl Specific TSTRING fields }
  222.   fJoinTableNames:=TStringList.Create;
  223.   fJoinAliasNames:=TStringList.Create;
  224.   fReplaces:=TStringList.Create;
  225.  
  226.   { Generic TSTRING fields }
  227.   fFields:=TStringList.Create;
  228.   fGroupFields:=TStringList.Create;
  229.   fSortFields:=TstringList.Create;
  230.   fUserParamsNames:=TStringList.Create;
  231.   fUserParamsValues:=TStringList.Create;
  232.   fAppName:=Application.exename;
  233.   fAuthor:='cbrooksbank@msn.com';
  234.   fAskPrinter:=true;
  235.  
  236.   fWait:=true;
  237.  
  238. end;
  239.  
  240. { ************************************************************************** }
  241. destructor TRRSQL65.Free;
  242. { ************************************************************************** }
  243. begin
  244.  
  245.   { SQL Specific TSTRING fields }
  246.   fJoinTableNames.Free;
  247.   fJoinAliasNames.Free;
  248.   fReplaces.free;
  249.  
  250.   { Generic TSTRING Fields }
  251.   fFields.free;
  252.   fGroupFields.free;
  253.   fSortFields.free;
  254.   fUserParamsNames.free;
  255.   fUserParamsValues.free;
  256.  
  257.   endruntimeinstance;
  258.  
  259.   inherited Free;
  260. end;
  261.  
  262.  
  263. { ************************************************************************** }
  264. procedure Register;
  265. { ************************************************************************** }
  266. begin
  267.   RegisterComponents('Data Access', [TRRSQL65]);
  268. end;
  269.  
  270. { ************************************************************************** }
  271. procedure TRRSQL65.LoadFromReport;
  272. { ************************************************************************** }
  273. { Using the fRepname and fLibname load object info from report defaults }
  274. var
  275.   hMyReport:Integer;
  276.   MyApp_,MyLib_,MyRep_: Pchar;
  277. begin
  278.   MyApp_:=StrAlloc(256);
  279.   MyLib_:=StrAlloc(256);
  280.   MyRep_:=StrAlloc(256);
  281.   try
  282.  
  283.     if ((flibname<>'') and (frepname<>'')) then
  284.     begin
  285.       StrPCopy(MyApp_,fAppName);
  286.       StrPCopy(MyLib_,fLibName);
  287.       StrPCopy(MyRep_,fRepName);
  288.  
  289.       hMyReport:=ChooseReport(MyApp_,MyLib_,MyRep_,StrBufSize(MyRep_));
  290.       if hMyReport>0 then
  291.       begin
  292.         try
  293.           LoadFromReportH(hMyReport);
  294.         finally
  295.           EndReport(hMyReport);
  296.         end;
  297.       end;
  298.  
  299.       if hMyReport<1 then MessageDlg('Cant load info on R&&R report '+ReportName,
  300.                                      mtError,[mbAbort],0);
  301.     end;
  302.   finally
  303.     StrDispose(MyApp_);
  304.     StrDispose(MyLib_);
  305.     StrDispose(MyRep_);
  306.   end;
  307. end;
  308.  
  309.  
  310. { ************************************************************************** }
  311. procedure TRRSQL65.LoadFromReportH(hMyReport:Integer);
  312. { ************************************************************************** }
  313.  
  314. { Using passed report handle load object info from report defaults }
  315.  
  316. begin
  317.  
  318.   { Clear SQL Specific TSTRING Fields }
  319.   fJoinTableNames.Clear;
  320.   fJoinAliasNames.Clear;
  321.   fReplaces.Clear;
  322.  
  323.   { Clear Generic TSTRING Fields }
  324.   fFields.Clear;
  325.   fGroupFields.Clear;
  326.   fSortFields.Clear;
  327.   fUserParamsNames.Clear;
  328.   fUserParamsValues.Clear;
  329.  
  330.   { Load SQL Specific Properties }
  331.   LoadJoins(hMyReport);
  332.   LoadReplaces(hMyReport);
  333.   LoadDataSource(hMyReport);
  334.  
  335.   { Load Generic Properties }
  336.   LoadFields(hMyReport);
  337.   LoadGroupFields(hMyReport);
  338.   LoadSortFields(hMyReport);
  339.   LoadUserParams(hMyReport);
  340.   LoadTitle(hMyReport);
  341.   LoadPages(hMyReport);
  342.   LoadTable(hMyReport);
  343.   LoadFilter(hMyReport);
  344.   LoadDests(hMyReport);
  345.   LoadPrinter(hMyReport);
  346.  
  347. end;
  348.  
  349. { ************************************************************************** }
  350. procedure TRRSQL65.setlibname(NewLibName:String);
  351. { ************************************************************************** }
  352. var
  353.   Designing:Boolean;
  354. begin
  355.   flibname:=NewLibName;
  356.   Designing:=(csDesigning in ComponentState);
  357.   if ((csReading in ComponentState) or (csLoading in ComponentState)) then
  358.     Designing:=false;
  359.  
  360.   if (Designing and (fLibName<>'') and (fRepName<>'') ) then
  361.   begin
  362.     if MessageDlg('Load Properties From Report ?',mtconfirmation,
  363.                   [mbNo,mbYes],0)=mrYes then loadfromreport;
  364.   end;
  365. end;
  366.  
  367. { ************************************************************************** }
  368. procedure TRRSQL65.LoadJoins(hReport:Integer);
  369. { ************************************************************************** }
  370. var
  371.   JoinTableName,JoinAliasName:Pchar;
  372. begin
  373.   JoinTableName:=StrAlloc(51);
  374.   JoinAliasName:=StrAlloc(51);
  375.   try
  376.     if GetFirstJoinInfo(hReport,JoinTableName,StrBufSize(JoinTableName),
  377.                      JoinAliasName,StrBufSize(JoinAliasName)) then
  378.     begin
  379.       fJoinTableNames.Add(StrPas(JoinTableName));
  380.       fJoinAliasNames.Add(StrPas(JoinAliasName));
  381.     end;
  382.  
  383.     while GetNextJoinInfo(hReport,JoinTableName,StrBufSize(JoinTableName),
  384.                           JoinAliasName,StrBufSize(JoinAliasName)) do begin
  385.       fJoinTableNames.Add(StrPas(JoinTableName));
  386.       fJoinAliasNames.Add(StrPas(JoinAliasName));
  387.     end;
  388.   finally
  389.     StrDispose(JoinTableName);
  390.     StrDispose(JoinAliasName);
  391.   end;
  392. end;
  393.  
  394. { ************************************************************************** }
  395. function TRRSQL65.Run:Boolean;
  396. { ************************************************************************** }
  397. begin
  398.   Result:=Execute;
  399. end;
  400.  
  401.  
  402. { ************************************************************************** }
  403. function TRRSQL65.Execute:Boolean;
  404. { ************************************************************************** }
  405. var
  406.   { Handle of report }
  407.   hReport: Integer;
  408.  
  409.   { Flags returned after report was run }
  410.   ECode:Integer;
  411.   cmdshow: Integer;
  412.   PageCount:LongInt;
  413.   EMsg:Pchar;
  414.   ErrorMess: String;
  415.  
  416.   AppName_,LibName_,RepName_:PChar;
  417. begin
  418.   EMsg:=StrAlloc(256);
  419.   AppName_:=StrAlloc(256);
  420.   LibName_:=StrAlloc(256);
  421.   RepName_:=StrAlloc(256);
  422.   try
  423.  
  424.     {Run the report }
  425.     Result:=false;
  426.  
  427.     { Convert Pascal type strings to C++ strings as expected by DLL }
  428.     StrPCopy(Appname_,fAppname);
  429.     StrPCopy(Libname_,fLibName);
  430.     StrPCopy(RepName_,fRepName);
  431.  
  432.     { If object specifys ask for report then blank out the report name }
  433.     { to make sure user is prompted for report name }
  434.     if fAskReport then  begin
  435.       fRepname:='';
  436.       StrPCopy(RepName_,fRepName);
  437.     end;
  438.  
  439.     hReport:=ChooseReport(Appname_,LibName_,RepName_,StrBufSize(RepName_));
  440.  
  441.     if hReport>0 then begin
  442.       try
  443.         { Pass all the propertys to RSREPORT.DLL }
  444.         SaveToReportH(hReport);
  445.  
  446.         { Run the report and then clean up }
  447.         cmdshow:=SW_SHOWNORMAL;
  448.         fErrorCode:='';
  449.         fErrorMessage:='';
  450.         ResetErrorInfo;
  451.         if ExecRunTime(hReport,fWait,cmdshow,@ECode,@PageCount,EMsg,StrBufSize(EMsg))
  452.         then Result:=True else begin
  453.           geterrorinfo(Emsg,StrBufSize(EMsg),@Ecode);
  454.           fErrorMessage:=StrPas(EMsg);
  455.  
  456.           case Ecode of
  457.             Ord('C'):fErrorCode:='Cancelled';
  458.             Ord('D'):fErrorCode:='Diagnostic';
  459.             Ord('I'):fErrorCode:='Iteration';
  460.             Ord('J'):fErrorCode:='Job Control';
  461.             Ord('L'):fErrorCode:='Library';
  462.             Ord('S'):fErrorCode:='Syntax';
  463.             Ord('V'):fErrorCode:='Value';
  464.             else
  465.               fErrorCode:=Chr(Ecode);
  466.           end;
  467.  
  468.           MessageDlg('R&&R Error : '+StrPas(EMsg),mtError,[mbAbort],0);
  469.         end;
  470.       finally
  471.         EndReport(hReport);
  472.       end;
  473.     end;
  474.     fLastErrorPage:=PageCount;
  475.     if hReport<1 then MessageDlg('Cant allocate handle for report '+fRepname,
  476.                                  mtError,[mbAbort],0)
  477.   finally
  478.     StrDispose(EMsg);
  479.     StrDispose(AppName_);
  480.     StrDispose(LibName_);
  481.     StrDispose(RepName_);
  482.   end;
  483. end;
  484.  
  485. { ************************************************************************** }
  486. procedure TRRSQL65.SetfJoinTableNames(Value:Tstrings);
  487. { ************************************************************************** }
  488. begin
  489.   fJoinTableNames.Assign(Value);
  490. end;
  491.  
  492. { ************************************************************************** }
  493. procedure TRRSQL65.SetfJoinAliasNames(Value:Tstrings);
  494. { ************************************************************************** }
  495. begin
  496.   fJoinAliasNames.Assign(Value);
  497. end;
  498.  
  499. { ************************************************************************** }
  500. procedure TRRSQL65.SetfReplaces(Value:Tstrings);
  501. { ************************************************************************** }
  502. begin
  503.   fReplaces.Assign(Value);
  504. end;
  505.  
  506. { ************************************************************************** }
  507. procedure TRRSQL65.SaveReplaces(hReport:Integer);
  508. { ************************************************************************** }
  509. var
  510.   i:Integer;
  511.   ThisReplace,ReplaceList:String;
  512.   Replaces_:Pchar;
  513. begin
  514.   Replaces_:=StrAlloc(256);
  515.   try
  516.     ReplaceList:='';
  517.     for i:=0 to (fReplaces.count-1) do begin
  518.       ThisReplace:=fReplaces[i];
  519.       if ThisReplace<>'' then ReplaceList:=ReplaceList+','+ThisReplace;
  520.     end;
  521.  
  522.     if ReplaceList<>'' then begin
  523.       ReplaceList:=Copy(ReplaceList,1,length(replacelist)-1);
  524.       StrPCopy(Replaces_,ReplaceList);
  525.       SetReplace(hReport,Replaces_);
  526.     end;
  527.   finally
  528.     StrDispose(Replaces_);
  529.   end;
  530. end;
  531.  
  532. { ************************************************************************** }
  533. procedure TRRSQL65.LoadReplaces(hReport:Integer);
  534. { ************************************************************************** }
  535. var
  536.   Replace:Pchar;
  537. begin
  538.   Replace:=StrAlloc(31);
  539.   try
  540.     if GetFirstReplace(hReport,Replace,StrBufSize(Replace)) then
  541.       fReplaces.Add(StrPas(Replace));
  542.     while GetNextReplace(hReport,Replace,StrBufSize(Replace)) do
  543.       fReplaces.Add(StrPas(Replace));
  544.   finally
  545.    StrDispose(Replace);
  546.   end;
  547. end;
  548.  
  549. { ************************************************************************** }
  550. procedure TRRSQL65.LoadDataSource(hReport:Integer);
  551. { ************************************************************************** }
  552. var
  553.   Source_:Pchar;
  554. begin
  555.   Source_:=StrAlloc(256);
  556.   try
  557.     if GetDataSource(hReport,source_,StrBufSize(source_)) then
  558.       fDataSource:=StrPas(Source_);
  559.   finally
  560.     StrDispose(Source_);
  561.   end;
  562. end;
  563.  
  564. { ************************************************************************** }
  565. procedure TRRSQL65.LoadUserParams(hReport:Integer);
  566. { ************************************************************************** }
  567. var
  568.   ParamName,ParamValue:Pchar;
  569. begin
  570.   ParamName:=StrAlloc(31);
  571.   ParamValue:=StrAlloc(31);
  572.   try
  573.     if GetFirstUserParam(hReport,ParamName,StrBufSize(ParamName),
  574.                       paramValue,StrBufSize(ParamValue)) then begin
  575.       fUserParamsNames.Add(StrPas(ParamName));
  576.       fUserParamsValues.Add(StrPas(ParamValue));
  577.     end;
  578.     while GetNextUserParam(hReport,ParamName,StrBufSize(ParamName),
  579.                            ParamValue,StrBufSize(ParamValue)) do begin
  580.       fUserParamsNames.Add(StrPas(ParamName));
  581.       fUSerParamsValues.Add(StrPas(ParamValue));
  582.     end;
  583.   finally
  584.     StrDispose(Paramname);
  585.     StrDispose(Paramvalue);
  586.   end;
  587. end;
  588.  
  589. { ************************************************************************** }
  590. procedure TRRSQL65.LoadFields(hReport:Integer);
  591. { ************************************************************************** }
  592. var
  593.   FieldName:Pchar;
  594. begin
  595.   FieldName:=StrAlloc(31);
  596.   try
  597.     if GetFirstFieldName(hReport,FieldName,StrBufSize(FieldName)) then
  598.       fFields.Add(StrPas(FieldName));
  599.     while GetNextFieldName(hReport,FieldName,StrBufSize(FieldName)) do
  600.       fFields.Add(StrPas(FieldName));
  601.   finally
  602.     StrDispose(FieldName);
  603.   end;
  604. end;
  605.  
  606. { ************************************************************************** }
  607. procedure TRRSQL65.LoadGroupFields(hReport:Integer);
  608. { ************************************************************************** }
  609. var
  610.   GroupField:Pchar;
  611. begin
  612.   GroupField:=StrAlloc(31);
  613.   try
  614.     if GetFirstGroupField(hReport,GroupField,StrBufSize(GroupField)) then
  615.       fGroupFields.Add(StrPas(GroupField));
  616.     while GetNextGroupField(hReport,GroupField,StrBufSize(GroupField)) do
  617.       fGroupFields.Add(StrPas(GroupField));
  618.   finally
  619.     StrDispose(GroupField);
  620.   end;
  621. end;
  622.  
  623. { ************************************************************************** }
  624. procedure TRRSQL65.LoadSortFields(hReport:Integer);
  625. { ************************************************************************** }
  626. var
  627.   SortField:Pchar;
  628. begin
  629.   SortField:=StrAlloc(31);
  630.   try
  631.     if GetFirstSortField(hReport,SortField,StrBufSize(SortField)) then
  632.       fSortFields.Add(StrPas(SortField));
  633.     while GetNextSortField(hReport,SortField,StrBufSize(SortField)) do
  634.       fSortFields.Add(StrPas(SortField));
  635.   finally
  636.     StrDispose(SortField);
  637.   end;
  638. end;
  639.  
  640. { ************************************************************************** }
  641. procedure TRRSQL65.SetRepName(NewRepName: String);
  642. { ************************************************************************** }
  643. var
  644.   Designing:Boolean;
  645. begin
  646.   fRepName:=NewRepName;
  647.   Designing:=(csDesigning in ComponentState);
  648.   if ((csReading in ComponentState) or (csLoading in ComponentState)) then
  649.     Designing:=false;
  650.  
  651.   if (Designing and (fLibName<>'') and (fRepName<>'') ) then
  652.   begin
  653.     if MessageDlg('Load Properties From Report ?',mtconfirmation,
  654.                   [mbYes,mbNo],0)=mrYes then loadfromreport;
  655.   end;
  656. end;
  657.  
  658. { ************************************************************************** }
  659. procedure TRRSQL65.SetfFields(Value:Tstrings);
  660. { ************************************************************************** }
  661. begin
  662.   fFields.Assign(Value);
  663. end;
  664.  
  665. { ************************************************************************** }
  666. procedure TRRSQL65.SetfGroupFields(Value:Tstrings);
  667. { ************************************************************************** }
  668. begin
  669.   fGroupFields.Assign(Value);
  670. end;
  671.  
  672. { ************************************************************************** }
  673. procedure TRRSQL65.SetfSortFields(Value:Tstrings);
  674. { ************************************************************************** }
  675. begin
  676.   fSortFields.Assign(Value);
  677. end;
  678.  
  679. { ************************************************************************** }
  680. procedure TRRSQL65.SetfUserParamsNames(Value:Tstrings);
  681. { ************************************************************************** }
  682. begin
  683.   fUserParamsNames.Assign(Value);
  684. end;
  685.  
  686. { ************************************************************************** }
  687. procedure TRRSQL65.SetfUserParamsValues(Value:Tstrings);
  688. { ************************************************************************** }
  689. begin
  690.   fUserParamsValues.Assign(Value);
  691. end;
  692.  
  693. { ************************************************************************** }
  694. procedure TRRSQL65.SetfActive(Value:Boolean);
  695. { ************************************************************************** }
  696. begin
  697.   if (csDesigning in ComponentState) and (Value=True) then execute;
  698. end;
  699.  
  700. { ************************************************************************** }
  701. procedure TRRSQL65.SetfAuthor(Value:String);
  702. { ************************************************************************** }
  703. begin
  704.   if Value<>'cbrooksbank@msn.com' then
  705.   messagedlg('Please send bugs/comments/enhancements to cbrooksbank@msn.com',mtInformation,
  706.               [mbOk],0);
  707.   fAuthor:='cbrooksbank@msn.com';
  708. end;
  709.  
  710. { ************************************************************************** }
  711. procedure TRRSQL65.LoadTitle(hReport:Integer);
  712. { ************************************************************************** }
  713. var
  714.   title_:Pchar;
  715. begin
  716.   title_:=StrAlloc(256);
  717.   try
  718.     if GetWinTitle(hReport,title_,StrBufSize(title_)) then
  719.       fWinTitle:=StrPas(title_);
  720.   finally
  721.     StrDispose(title_);
  722.   end;
  723. end;
  724.  
  725. { ************************************************************************** }
  726. procedure TRRSQL65.LoadPages(hReport:Integer);
  727. { ************************************************************************** }
  728. begin
  729.   GetBeginPage(hReport,@fBeginPage);
  730.   GetEndPage(hReport,@fEndPage);
  731.   GetCopies(hReport,@fCopies);
  732. end;
  733.  
  734. { ************************************************************************** }
  735. procedure TRRSQL65.LoadTable(hReport:Integer);
  736. { ************************************************************************** }
  737. var
  738.   table_:Pchar;
  739. begin
  740.   Table_:=StrAlloc(256);
  741.   try
  742.     if GetMasterTableName(hReport,table_,StrBufSize(table_)) then
  743.       fMasterTableName:=StrPas(table_);
  744.   finally
  745.     StrDispose(Table_);
  746.   end;
  747. end;
  748.  
  749.  
  750. { ************************************************************************** }
  751. procedure TRRSQL65.LoadFilter(hReport:Integer);
  752. { ************************************************************************** }
  753. var
  754.   filter_:Pchar;
  755. begin
  756.   filter_:=StrAlloc(256);
  757.   try
  758.     if getFilter(hReport,filter_,StrBufSize(filter_)) then
  759.       fFilter:=StrPas(filter_);
  760.   finally
  761.     StrDispose(filter_);
  762.   end;
  763. end;
  764.  
  765. { ************************************************************************** }
  766. procedure TRRSQL65.LoadDests(hReport:Integer);
  767. { ************************************************************************** }
  768. var
  769.   Dest_:Pchar;
  770.   DestStr:String;
  771. begin
  772.   Dest_:=StrAlloc(256);
  773.   try
  774.  
  775.     { Load fExportDest}
  776.     if getExportDest(hReport,Dest_) then
  777.     begin
  778.       DestStr:=StrPas(Dest_);
  779.       if DestStr[1]='D' then
  780.         fExportDest:=rredDisplay;
  781.       if DestStr[1]='F' then
  782.         fExportDest:=rredFile;
  783.       if DestStr[1]='P' then
  784.         fExportDest:=rredPrinter;
  785.     end;
  786.  
  787.     { Load fOutPutDest }
  788.     if getOutputDest(hReport,Dest_) then
  789.     begin
  790.       DestStr:=StrPas(Dest_);
  791.       if DestStr[1]='D' then
  792.         fOutPutDest:=rrdDisplay;
  793.       if DestStr[1]='A' then
  794.         fOutPutDest:=rrdTextFile;
  795.       if DestStr[1]='T' then
  796.         fOutPutDest:=rrdTextFile;
  797.       if DestStr[1]='P' then
  798.         fOutPutDest:=rrdPrinter;
  799.       if DestStr[1]='W' then
  800.         fOutPutDest:=rrdWorksheet;
  801.       if DestStr[1]='X' then
  802.         fOutPutDest:=rrdXBase;
  803.       if DestStr[1]='?' then
  804.         fOutPutDest:=rrdInteractive;
  805.     end;
  806.  
  807.     { Load fOutputFile }
  808.     if getOutputDest(hReport,Dest_) then
  809.       fOutPutFile:=StrPas(Dest_);
  810.   finally
  811.     StrDispose(Dest_);
  812.   end;
  813.  
  814. end;
  815.  
  816. { ************************************************************************** }
  817. procedure TRRSQL65.LoadPrinter(hReport:Integer);
  818. { ************************************************************************** }
  819. var
  820.   Printer_,Port_:Pchar;
  821. begin
  822.   Printer_:=StrAlloc(256);
  823.   Port_:=StrAlloc(256);
  824.   try
  825.     if getPrinter(hReport,Printer_,StrBufSize(Printer_)) then
  826.       fPrinterName:=StrPas(Printer_);
  827.     if getPrinterPort(hReport,Port_,StrBufSize(Port_)) then
  828.       fPrinterPort:=StrPas(Port_);
  829.   finally
  830.     StrDispose(Printer_);
  831.     StrDispose(Port_);
  832.   end;
  833. end;
  834.  
  835. { ************************************************************************** }
  836. procedure TRRSQL65.SaveToReportH(hReport:Integer);
  837. { ************************************************************************** }
  838.  
  839. { Given a report handle save object properties to the report }
  840. { Pass all the propertys to RSREPORT.DLL }
  841.  
  842. var
  843.   { Temp vars to hold Pchar versions of String properties }
  844.   DataSource_,PrinterName_:PChar;
  845.   PrinterPort_,PassWord_,UserName_:PChar;
  846.   filter_: Pchar;
  847.   MasterTableName_,MemoName_,OutputFile_,WinTitle_: Pchar;
  848.   Tablename_,Databasename_,Where_:Pchar;
  849.  
  850.   CharString:String;
  851.   SiField,SiField2:Pchar;
  852.   datadir_,imagedir_:Pchar;
  853.  
  854.   i,maxi:Integer;
  855.  
  856. begin
  857.   DataSource_:=StrAlloc(256);
  858.   PrinterName_:=StrAlloc(256);
  859.   PrinterPort_:=StrAlloc(31);
  860.   PassWord_:=StrAlloc(31);
  861.   UserName_:=StrAlloc(31);
  862.   filter_:=StrAlloc(256);
  863.   MasterTableName_:=StrAlloc(256);
  864.   MemoName_:=StrAlloc(256);
  865.   OutputFile_:=StrAlloc(256);
  866.   WinTitle_:=StrAlloc(256);
  867.   TableName_:=StrAlloc(256);
  868.   DatabaseName_:=StrAlloc(256);
  869.   Where_:=StrAlloc(256);
  870.   SiField:=StrAlloc(256);
  871.   SiField2:=StrAlloc(256);
  872.   datadir_:=StrAlloc(256);
  873.   imagedir_:=StrAlloc(256);
  874.   try
  875.  
  876.     if AskPrinter then fPrinterName:='?';
  877.  
  878.     { Convert Pascal type strings to C++ strings as expected by DLL }
  879.     StrPCopy(DataSource_,fDataSource);
  880.     StrPCopy(Filter_,fFilter);
  881.     StrPCopy(MasterTableName_,fMasterTableName);
  882.     StrPCopy(MemoName_,fMemoName);
  883.     StrPCopy(OutputFile_,fOutputFile);
  884.     StrPCopy(Password_,fPassword);
  885.     StrPCopy(Printername_,fPrinterName);
  886.     StrPCopy(PrinterPort_,fPrinterPort);
  887.     StrPCopy(UserName_,fUserName);
  888.     StrPCopy(WinTitle_,fWinTitle);
  889.     StrPCopy(Databasename_,fDatabasename);
  890.     StrPCopy(Where_,fwhere);
  891.     StrPCopy(ImageDir_,fimagedir);
  892.     StrPCopy(DataDir_,fdatadir);
  893.  
  894.     SetBeginPage(hReport,fBeginPage);
  895.     SetCopies(hReport,fCopies);
  896.     SetDisplayErrors(hReport,fDisplayErrors);
  897.     SetDisplayStatus(hReport,FDisplayStatus);
  898.     SetEndPage(hReport,fEndPage);
  899.  
  900.     CharString:=Copy('DFP',Ord(fExportDest)+1,1);
  901.     SetExportDest(hReport,CharString[1]);
  902.  
  903.     SetFilter(hReport,Filter_);
  904.  
  905.     CharString:=Copy('SEO?',Ord(fFilterUsage)+1,1);
  906.     SetFilterUsage(hReport,CharString[1]);
  907.  
  908.     if fMasterTableName<>''then
  909.       SetMasterTableName(hReport,MasterTableName_);
  910.  
  911.     if fMemoName<>'' then
  912.       SetMemoName(hReport,MemoName_);
  913.  
  914.     CharString:=Copy('DAPWX?CMR',Ord(fOutputDest)+1,1);
  915.     SetOutputDest(hReport,CharString[1]);
  916.  
  917.     SetOutPutFile(hReport,OutputFile_);
  918.     SetPassword(hReport,Password_);
  919.     SetPreventEscape(hReport,fPreventEscape);
  920.     SetStatusEveryPage(hReport,fStatusEveryPage);
  921.     SetTestPattern(hReport,fTestPattern);
  922.     SetUserName(hReport,Username_);
  923.  
  924.     CharString:=Copy('0123',Ord(fWinBorderStyle)+1,1);
  925.     SetWinBorderStyle(hReport,Ord(CharString[1])-Ord('0'));
  926.  
  927.     SetWinControlBox(hReport,fWinControlBox);
  928.     SetWinHeight(hReport,fWinHeight);
  929.     SetWinLeft(hReport,fWinLeft);
  930.     SetWinMaxButton(hReport,fWinMaxButton);
  931.     SetWinMinButton(hReport,fWinMinButton);
  932.     SetWinParentHandle(hReport,fWinParentHandle);
  933.     SetWinTitle(hReport,WinTitle_);
  934.     SetWinTop(hReport,fWinTop);
  935.     SetWinWidth(hReport,fWinWidth);
  936.  
  937.     { Set sort fields }
  938.     for i:=0 to (fSortFields.Count-1) do begin
  939.       if ((fSortFields[i]<>'') and
  940.          (Pos('RECNO',UpperCase(fSortFields[i]))=0)) then begin
  941.         StrPCopy(SiField,fSortFields[i]);
  942.         SetSortField(hReport,SiField,i+1);
  943.       end;
  944.     end;
  945.  
  946.     { Set Group Fields }
  947.     for i:=0 to (fGroupFields.Count-1) do begin
  948.       if fGroupFields[i]<>'' then begin
  949.         StrPCopy(SiField,fGroupFields[i]);
  950.         SetGroupField(hReport,SiField,i+1);
  951.       end;
  952.     end;
  953.  
  954.     { Set join information }
  955.     maxi:=fJoinTableNames.count;
  956.     if fJoinAliasNames.Count<maxi then maxi:=fJoinAliasNames.Count;
  957.     dec(maxi);
  958.     for i:=0 to maxi do begin
  959.       if fJoinTableNames[i]<>'' then begin
  960.         StrPCopy(SiField,fJoinTableNames[i]);
  961.         StrPCopy(SiField2,fJoinAliasNames[i]);
  962.         SetJoinInfo(hReport,SiField,Sifield2,i+1);
  963.       end;
  964.     end;
  965.  
  966.     { Set user paramaters }
  967.     for i:=0 to (fUserParamsNames.Count-1) do begin
  968.       if fUserParamsNames[i]<>'' then begin
  969.         StrPCopy(SiField,fUserParamsNames[i]);
  970.         StrPCopy(SiField2,fUserParamsValues[i]);
  971.         SetUserParam(hreport,SiField,SiField2);
  972.       end;
  973.     end;
  974.  
  975.     if ((fPrinterName<>'') or AskPrinter) then
  976.     begin
  977.       SetPrinter(hReport,PrinterName_);
  978.       SetPrinterPort(hReport,PrinterPort_);
  979.     end;
  980.  
  981.     if AskDataSource then
  982.       ChooseDataSource(hReport,Datasource_,StrBufSize(Datasource_));
  983.  
  984.  
  985.     if AskTable then ChooseTable(hReport,Tablename_,StrBufSize(TableName_),
  986.                                  DataSource_,StrBufSize(DataSource_),
  987.                                  Databasename_,StrBufSize(Databasename_));
  988.  
  989.     if fDataSource<>'' then SetDataSource(hReport,DataSource_);
  990.  
  991.     if fwhere<>'' then SetWhere(hReport,where_);
  992.  
  993.     if fimagedir<>'' then SetImageDir(hreport,imagedir_);
  994.     if fdatadir<>'' then SetDataDir(hreport,datadir_);
  995.  
  996.     SaveReplaces(hReport);
  997.   finally
  998.     StrDispose(DataSource_);
  999.     StrDispose(PrinterName_);
  1000.     StrDispose(PrinterPort_);
  1001.     StrDispose(PassWord_);
  1002.     StrDispose(UserName_);
  1003.     StrDispose(filter_);
  1004.     StrDispose(MasterTableName_);
  1005.     StrDispose(MemoName_);
  1006.     StrDispose(Outputfile_);
  1007.     StrDispose(WinTitle_);
  1008.     StrDispose(TableName_);
  1009.     StrDispose(DatabaseName_);
  1010.     StrDispose(Where_);
  1011.     StrDispose(SiField);
  1012.     StrDispose(SiField2);
  1013.     StrDispose(datadir_);
  1014.     StrDispose(imagedir_);
  1015.  end;
  1016.  
  1017. end;
  1018.  
  1019.  
  1020. { ************************************************************************** }
  1021. function TRRSQL65.SaveToFile(MyFile:String):Boolean;
  1022. { ************************************************************************** }
  1023. var
  1024.   hReport:Integer;
  1025.   MyFile_,MyApp_,MyLib_,MyRep_:PChar;
  1026. begin
  1027.   MyFile_:=StrAlloc(256);
  1028.   MyApp_:=StrAlloc(256);
  1029.   MyLib_:=StrAlloc(256);
  1030.   MyRep_:=StrAlloc(256);
  1031.   try
  1032.  
  1033.     Result:=false;
  1034.     StrPCopy(MyApp_,fAppName);
  1035.     StrPCopy(MyLib_,fLibName);
  1036.     StrPCopy(MyRep_,fRepName);
  1037.  
  1038.     hReport:=ChooseReport(MyApp_,MyLib_,MyRep_,StrBufSize(MyRep_));
  1039.     try
  1040.       if hReport>0 then
  1041.       begin
  1042.         StrPCopy(MyFile_,MyFile);
  1043.         savetoreportH(hReport);
  1044.         if writeRunTimeRecord(hReport,MyFile_) then result:=true;
  1045.       end;
  1046.     finally
  1047.       EndReport(hReport);
  1048.     end;
  1049.   finally
  1050.     StrDispose(MyFile_);
  1051.     StrDispose(MyApp_);
  1052.     StrDispose(MyLib_);
  1053.     StrDispose(MyRep_);
  1054.   end;
  1055. end;
  1056.  
  1057. { ************************************************************************** }
  1058. function TRRSQL65.LoadFromFile(MyFile:String):Boolean;
  1059. { ************************************************************************** }
  1060. var
  1061.   hReport:Integer;
  1062.   MyFile_,MyApp_,MyLib_,MyRep_:PChar;
  1063. begin
  1064.   MyFile_:=StrAlloc(256);
  1065.   MyApp_:=StrAlloc(256);
  1066.   MyLib_:=StrAlloc(256);
  1067.   MyRep_:=StrAlloc(256);
  1068.   try
  1069.  
  1070.     Result:=false;
  1071.     StrPCopy(MyApp_,fAppName);
  1072.     StrPCopy(MyLib_,fLibName);
  1073.     StrPCopy(MyRep_,fRepName);
  1074.  
  1075.     StrPCopy(MyFile_,MyFile);
  1076.     hReport:=getRunTimeRecord(MyApp_,MyFile_);
  1077.     if hReport>0 then
  1078.     begin
  1079.       try
  1080.         { Load report information into this object }
  1081.         Result:=true;
  1082.         loadfromreporth(hReport);
  1083.       finally
  1084.         EndReport(hReport);
  1085.       end;
  1086.     end;
  1087.   finally
  1088.     StrDispose(MyFile_);
  1089.     StrDispose(MyApp_);
  1090.     StrDispose(MyLib_);
  1091.     StrDispose(MyRep_);
  1092.   end;
  1093. end;
  1094.  
  1095.  
  1096. end.
  1097.